function [ D ] = osl_neuromag_grad_baseline_correction(spmfilename, scanner_type, inv)

    if nargin<2,
        scanner_type='vector_view';
    end;
    
    if nargin<3,
        inv=1;
    end;
    
    D = spm_eeg_load(spmfilename);

    % this bit is needed to correct for error in the fieldtrip code in
    % SPM8
    correct_factor=1/0.017; % gradiometer coils are 17mm apart
    %correct_factor=1;
    
    switch scanner_type,
        case 'vector_view',
            warning('osl_neuromag_grad_baseline_correction: Doing VectorView Neuromag gradiometer baseline correction.');

            D=correct_planar_grads(spmfilename,['fixed_tra.mat'],correct_factor);

        case 'triux',
            warning('osl_neuromag_grad_baseline_correction: Doing Triux Neuromag gradiometer baseline correction.');

            D=correct_planar_grads_triux(spmfilename,correct_factor);

        otherwise,
            error('Unsupported scanner type');            
    end;

    D.save;

end

